<div class="nav-container">
	<div class="container">
		<div class="row">
			<div class="col-xs-12">
				<ul id="nav" class="sf-menu">
					<?php 
                        $category=Category::model()->findAll('category_parent is null');
                        
                        $i=1;                                	
                        foreach ($category as $cat) {
                            $cat_id=$cat['category_id'];
                            $cat_name=$cat['category_name'];
                            
                            //get subcat
                            $criteriaSubCat=new CDbCriteria(array(
                                'condition'=>'category_parent='.$cat_id,
                                'order'=>'category_name asc',
                            ));
                            $sub_cat=Category::model()->findAll($criteriaSubCat);                                     
                            if(count($sub_cat)==0){                                             
                    ?>
                    <li class="level0 nav-<?php echo $i; if($i==count($sub_cat)){echo ' last';}elseif($i==1){echo ' first';}?> level-top">
						<?php
                            echo CHtml::link('<span>'.$cat_name.'</span>',array('Browser/ViewBy','category_id'=>$cat_id),array('class'=>'level-top'));
                            //echo "<a href='".$this->createUrl('/danh-muc/'.$cat_id)."/".FormHelper::ConvertTitleToUrl($cat_name).".html'>".$cat_name."</a>";	
                        ?>
					</li>
					<?php }else{ ?>
					<li class="level0 nav-<?php echo $i; ?> level-top parent">
                        <?php
                            echo CHtml::link('<span>'.$cat_name.'</span>',array('Browser/ViewBy','category_id'=>$cat_id),array('class'=>'level-top'));
                            //echo CHtml::link('<span>'.$cat_name.'</span>',DOMAIN.'danh-muc/'.$cat_id.'/'.FormHelper::ConvertTitleToUrl($cat_name).'.html',array('class'=>'level-top'));	
                        ?>
						<ul class="level0">
                            <?php 
                                $y=1;
                                foreach ($sub_cat as $sub_cat_value) {                                                
                            ?>
                            <?php
                            	$brand=Brand::model()->findAll('category_id='.$sub_cat_value['category_id']);
                                if(count($brand)==0){
                            ?>
							<li class="level1 nav-<?php echo $i; ?>-<?php echo $y; if($y==count($sub_cat)){echo ' last';}elseif($y==1){echo ' first';}?>">
								<?php
                                    echo CHtml::link('<span>'.$sub_cat_value['category_name'].'</span>',array('Browser/ViewBy','category_id'=>$sub_cat_value['category_id']));
                                    //echo CHtml::link('<span>'.$sub_cat_value['category_name'].'</span>',DOMAIN.'danh-muc/'.$sub_cat_value['category_id'].'/'.FormHelper::ConvertTitleToUrl($sub_cat_value['category_name']).'.html');        	
                                ?>
							</li>
                            <?php
                            	}else{
                            ?>
							<li class="level1 nav-<?php echo $i; ?>-<?php echo $y;?> parent">
								<?php
                                    echo CHtml::link('<span>'.$sub_cat_value['category_name'].'</span>',array('Browser/ViewBy','category_id'=>$sub_cat_value['category_id']));	
                                ?>
								<ul class="level1">
                                <?php
                                	$z=0;
                                    foreach ($brand as $brandname) {
                                ?>
									<li class="level2 nav-<?php echo $i; ?>-<?php echo $y;?>-<?php echo $z; if($z==count($brand)){echo ' last';}elseif($z==1){echo ' first';}?>">
										<?php
                                        	echo CHtml::link('<span>'.$brandname['brand_name'].'</span>',array('Browser/ViewBy','category_id'=>$sub_cat_value['category_id'],'brand_id'=>$brandname['brand_id']));
                                        ?>
									</li>
                                <?php
                                    $z++;
                                	}
                                ?>
								</ul>
							</li>
                            <?php
                            	}
                            ?>
                            <?php
                                $y++;
                                }
                            ?>
						</ul>
					</li>
                    <?php 
                    	} $i++;
                        }
                    ?>
				</ul>
				<div class="sf-menu-block">
					<div id="menu-icon">
						Danh mục
					</div>
					<ul class="sf-menu-phone">
                        <?php                                    
                            $i=1;                                	
                            foreach ($category as $cat) {
                                $cat_id=$cat['category_id'];
                                $cat_name=$cat['category_name'];
                                
                                //get subcat
                                $sub_cat=Category::model()->findAll('category_parent='.$cat_id);
                                if(count($sub_cat)==0){                                            
                        ?>	
						<li class="level0 nav-<?php echo $i; if($i==count($sub_cat)){echo ' last';}elseif($i==1){echo ' first';} ?> level-top">
							<a href="<?php echo CHtml::normalizeUrl(array('Browser/ViewBy','category_id'=>$cat_id)); ?>" class="level-top"><span><?php echo $cat_name; ?></span></a>
						</li>
                        <?php }else{ ?>
						<li class="level0 nav-<?php echo $i; ?> level-top parent">
							<a href="<?php echo CHtml::normalizeUrl(array('Browser/ViewBy','category_id'=>$cat_id)); ?>" class="level-top"><span><?php echo $cat_name; ?></span></a>
							<ul class="level0">
                                <?php 
                                    $y=1;
                                    foreach ($sub_cat as $sub_cat_value) {
                                        $brand=Brand::model()->findAll('category_id='.$sub_cat_value['category_id']);
                                        if(count($brand)==0){
                                ?>
								<li class="level1 nav-<?php echo $i; ?>-<?php echo $y; if($y==count($sub_cat)){echo ' last';}elseif($y==1){echo ' first';}?>">
									<a href="<?php echo CHtml::normalizeUrl(array('Browser/ViewBy','category_id'=>$sub_cat_value['category_id'])); ?>"><span><?php echo $sub_cat_value['category_name']; ?></span></a>
								</li>
                                <?php
                                	}else{
                                ?>
                                <li class="level1 nav-<?php echo $i; ?>-<?php echo $y;?> parent">
									<a href="<?php echo CHtml::normalizeUrl(array('Browser/ViewBy','category_id'=>$sub_cat_value['category_id'])); ?>"><span><?php echo $sub_cat_value['category_name']; ?></span></a>
									<ul class="level1">
                                    <?php
                                    	$z=0;
                                        foreach ($brand as $brandname) {
                                    ?>
										<li class="level2 nav-<?php echo $i; ?>-<?php echo $y;?>-<?php echo $z; if($z==count($brand)){echo ' last';}elseif($z==1){echo ' first';}?>">
											<a href="<?php echo CHtml::normalizeUrl(array('Browser/ViewBy','brand_id'=>$brandname['brand_id'])); ?>"><span><?php echo $brandname['brand_name']; ?></span></a>
										</li>
                                        <?php } $z++; ?>
									</ul>
								</li>
                                <?php
                                	}$y++;}
                                ?>
							</ul>
                            <?php }$i++;} ?>
						</li>
					</ul>
				</div>
			</div>
		</div>
		<div class="clear">
		</div>
	</div>
</div>